<template>
	<view class="recharge-page">
		<u-navbar title="提现" :autoBack="true" :placeholder="true" bgColor="rgba(0,0,0,0.0)">
			<view slot="right" style="font-size: 26rpx;" @click="gojl">
				提现记录
			</view>
		</u-navbar>
		<view class="content">
			<view class="box">
				<view class="title">
					<view class="title-text"> 
						提现金额
					</view>
				</view>
				<view class="item">
					<u--input type="number" placeholder="请输入提现金额" border="none" v-model="num"></u--input>
				</view>
				<view class="title">
					<view class="title-text">
						提现方式
					</view>
				</view>
				<view class="item" @click="show = true">
					<view class="item-tetx" v-if="type==''">
						选择提现方式
					</view>
					<view class="item-tetx2" v-else>
						{{type}}
					</view>
				</view>
				<view class="title">
					<view class="title-text">
						提现账户
					</view>
				</view>
				<view class="item" @click="gowithdrawal">
					<view class="item-tetx" v-if="account==''">
						选择提现账户
					</view>
					<view class="item-tetx2" v-else>
						{{account}}
					</view>
				</view>
				<view class="title">
					<view class="title-text">
						验证码 
					</view>
				</view>
				<view class="item">
					<u-input placeholder="请输入谷歌验证码或手机验证码" type="number" border="none" maxlength="6" v-model="alipay_code">
						<template slot="suffix">
							<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
							<u-button @tap="getCode" :text="tips" type="success"
								color="linear-gradient(90deg, rgb(254, 138, 3) 0%, rgb(250, 89, 0) 100%)"
								size="mini"></u-button>
						</template>
					</u-input>
				</view>
				<view class="tips">
					当前用户余额：<text>￥{{userinfo.balance}}</text>
				</view>
			</view>
			<view class="btn">
				<u-button size="large" color="#fa922e" type="primary" text="确认提现" @click="goquer"></u-button>
			</view>
		</view>
		<u-picker @cancel="show = false" :show="show" :columns="columns" @confirm="confirm"></u-picker>
		<u-picker ref="uPicker" @cancel="cancel" :show="show2" keyName="payName" :columns="columns2"
			@confirm="confirm2"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num: '',
				show: false,
				show2: false,
				columns: [
					['支付宝', '微信', '银行卡']
				],
				columns2: [],
				account: '',
				payid: '',
				userinfo: {},
				type: '支付宝',
				alipay_code: '',
				tips: '',
			}
		},
		onShow() {
			this.getuserinfo()
		},
		methods: {
			gojl(){
				uni.navigateTo({
					url:'/pages/manager/withdrawal-jl/index'
				})
			},
			getuserinfo() {
				this.$Request({
					method: 'GET',
					url: '/api/member/balance/getInfo',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 200) {
						this.userinfo = res.data
						console.log(this.userinfo)
					}
				})
			},
			cancel() {
				this.columns2 = []
				this.show2 = false
			},
			goquer() {
				if (this.num == '') {
					uni.showToast({
						title: '请输入提现金额！',
						icon: 'none'
					})
					return
				}
				if (this.account == '') {
					uni.showToast({
						title: '请选择提现账户！',
						icon: 'none'
					})
					return
				}
				if (this.alipay_code == '') {
					uni.showToast({
						title: '请输入验证码！',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					mask: true
				})
				let params = {
					payoutsAmount: this.num,
					payoutsType: 1,
					payoutsConfigId: this.payid
				}
				if (this.type == '支付宝') {
					params.payoutsType = 2
				}
				if (this.type == '微信') {
					params.payoutsType = 1
				}
				if (this.type == '银行卡') {
					params.payoutsType = 4
				}
				this.$Request({
					method: 'POST',
					url: '/api/member/balance/payoutsApply',
					data: params,
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.num = ''
						this.account = ''
					}
				})

			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			gowithdrawal() {
				if (this.type == '支付宝') {
					this.getlist('/api/member/payoutInfo/zfb/list')
				}
				if (this.type == '微信') {
					this.getlist('/api/member/payoutInfo/wx/list')
				}
				if (this.type == '银行卡') {
					this.getlist('/api/member/payoutInfo/bank/list')
				}
			},
			getlist(url) {
				uni.showLoading({
					mask: true
				})
				let params = {
					pageNum: this.page,
					pageSize: 100
				}
				this.$Request({
					method: 'GET',
					url: url,
					data: params,
					ismsg: false,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.$refs.uPicker.setColumnValues(1, res.rows)
						if (res.rows.length < 1) {
							if (this.type == '支付宝') {
								uni.showToast({
									title: '请先添加支付宝账户！',
									icon: 'none'
								})
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/my/account/receive/list?type=' + 1
									})
								}, 500)
								return
							}
							if (this.type == '微信') {
								uni.showToast({
									title: '请先添加微信账户！',
									icon: 'none'
								})
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/my/account/receive/list?type=' + 2
									})
								}, 500)
								return
							}
							if (this.type == '银行卡') {
								uni.showToast({
									title: '请先添加银行卡账户！',
									icon: 'none'
								})
								setTimeout(() => {
									uni.navigateTo({
										url: '/pages/my/account/receive/list?type=' + 3
									})
								}, 500)
								return
							}

						}
						this.show2 = true
					}
				})
			},
			confirm(e) {
				this.type = e.value[0]
				this.columns2 = []
				this.account = ''
				this.show = false
			},
			confirm2(e) {
				this.columns2 = []
				this.account = e.values[0][0].payName
				this.payid = e.values[0][0].id
				this.show2 = false
			},

		}
	}
</script>

<style lang="scss" scoped>
	.recharge-page {
		min-height: calc(100vh - 91rpx);
		background-image: url('../../../static/goods/top-bg.png');
		background-size: 100% 561rpx;
		background-repeat: no-repeat;

		.content {
			padding: 30rpx;

			.box {
				.title {
					display: flex;
					justify-content: space-between;
					font-size: 28rpx;

					.title-text {
						color: #333;
						font-weight: bold;
					}
				}

				.item {
					padding: 20rpx 30rpx;
					background-color: #fff;
					border-radius: 20rpx;
					box-shadow: 0rpx 0rpx 16rpx 1rpx rgba(0, 0, 0, 0.08);
					margin: 30rpx 0;

					.item-tetx {
						font-size: 28rpx;
						color: #c3c3c3;
						padding: 5rpx 0;
					}

					.item-tetx2 {
						color: #000000;
					}
				}

				.tips {
					font-size: 32rpx;
					color: #333;

					text {
						color: #ff0000;
						font-weight: bold;
					}
				}
			}

			.btn {
				border-radius: 15px;
				overflow: hidden;
				margin-top: 50rpx;
			}
		}
	}
</style>